package com.e2u.test;

import java.io.File;

import com.e2u.classloader.FileSystemClassLoader;
import com.e2u.util.FileWatchdog;
import com.e2u.util.SystemUtil;

public class HotswapFileWatchdog extends FileWatchdog
{
	private String rootDir = null;
	public HotswapFileWatchdog(String dir, String filename)
	{
		super(dir + File.separatorChar + filename);
		rootDir = dir;
	}
	@Override
	protected void doOnChange()
	{
		FileSystemClassLoader fscl = new FileSystemClassLoader(rootDir);
		
		String className = fscl.pathToClassName(filename);
		try
		{
			Class<?> clazz = fscl.loadClass(className, true);
			SystemUtil.invoke(clazz, "sayHello");
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}

}
